<template>
  <div class="container">
    <el-card shadow="always" class="custom-card">
      <template #header>
        <div class="header">{{ yard_name }}</div>
      </template>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-image :src="yard_image" style="justify-content: center"></el-image>
        </el-col>
      </el-row>
      <el-row :gutter="20" class="details">
        <el-col :span="12">
          <p><strong>校区:</strong> {{ campusname }}</p>
        </el-col>
        <el-col :span="12">
          <p><strong>场地名称:</strong> {{ yard_name }}</p>
        </el-col>
        <el-col :span="12">
          <p><strong>运动类型:</strong> {{ yard_type }}</p>
        </el-col>
        <el-col :span="12">
          <p><strong>开放时间:</strong> {{ availabletime }}</p>
        </el-col>
        <el-col :span="12">
          <p><strong>状态:</strong> {{ yard_status }}</p>
        </el-col>
        <el-col :span="12">
          <p><strong>租金:</strong> {{ hourrate }}</p>
        </el-col>
        <el-col :span="24">
          <p class="yard-text"><strong>简介:</strong> {{ yard_text }}</p>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24" style="text-align: center;">
          <el-button type="primary" @click="Reserve" v-if="status()">预定</el-button>
          <el-button type="danger" plain disabled v-else>无法预定</el-button>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()
const yard_id = ref('')
const yard_name = ref('')
const campusname = ref('')
const yard_type = ref('')
const availabletime = ref('')
const yard_text = ref('')
const yard_image = ref('')
const yard_status = ref('')
const hourrate = ref('')

function Reserve() {
  router.push({
    name: "reserve",
    query: {
      yard_id: yard_id.value,
      yard_name: yard_name.value,
      campusname: campusname.value,
      yard_type: yard_type.value,
      availabletime: availabletime.value,
      yard_text: yard_text.value,
      yard_image: yard_image.value,
      yard_status: yard_status.value,
      hourrate: hourrate.value,
    },
  });
}

onMounted(() => {
  const yardInfo = route.query
  yard_id.value = yardInfo.yard_id
  yard_name.value = yardInfo.yard_name
  campusname.value = yardInfo.campusname
  yard_type.value = yardInfo.yard_type
  availabletime.value = yardInfo.availabletime
  yard_text.value = yardInfo.yard_text
  yard_image.value = yardInfo.yard_image
  yard_status.value = yardInfo.yard_status
  hourrate.value = yardInfo.hourrate

  console.log('Yard Info:', yardInfo)
})

function status() {
  return yard_status.value === '开放'
}
</script>

<style scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  padding: 20px;
  background-color: #e0f7fa;
}

.custom-card {
  width: 100%;
  max-width: 800px;
  border-radius: 10px;
  overflow: hidden;
  background-color: #ffffff;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  transition: transform 0.3s, box-shadow 0.3s;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.custom-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.2);
}

.header {
  font-size: 28px;
  font-weight: bold;
  text-align: center;
  color: #00796b;
  padding: 10px 0;
}

.yard-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 10px;
}

.details {
  padding: 20px;
  overflow-y: auto;
}

.details p {
  margin: 10px 0;
  font-size: 18px;
  color: #37474f;
}

.details strong {
  color: #00796b;
}

.yard-text {
  margin-top: 20px;
  white-space: pre-wrap;
}
</style>
